package com.project.srtp.common.biz;

/**
 * @author 曹行阳
 * @version 0.1
 * @date 2025/3/26 9:23
 * 用户上下文持有器
 */
public class UserContextHolder {
    private static final ThreadLocal<UserContext> contextHolder = new ThreadLocal<>();

    public static void setContext(UserContext context) {
        contextHolder.set(context);
    }

    public static UserContext getContext() {
        return contextHolder.get();
    }

    public static Long getUserId() {
        UserContext context = contextHolder.get();
        return context != null ? context.getUserId() : null;
    }

    public static void clear() {
        contextHolder.remove();
    }
}
